// pages/tixian/tixian.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    rule_state:false,
    xieyi:"",
    weixin_content:"",
    bank_content:"",
    zfb_content:"",
    hid:"",
    bank_id:'',
    bank_card:'',
    bank_address:'',
    bank_user:'',
    zfb_id:'',
    zfb_name:'',
    zfb_number:'',
    fee:'0.00',
    position:'0'
  },
  radio_chose:function(e){
    var index = e.currentTarget.dataset.index;
    this.setData({
      position:index
    })
    if(index == '0')
    {
      this.setData({
        xieyi:this.data.bank_content
      })
    }else if(index == '1')
    {
      this.setData({
        xieyi:this.data.weixin_content
      })
    }else if(index == '2')
    {
      this.setData({
        xieyi:this.data.zfb_content
      })
    }
  },
  // 提现输入
  changemoney:function(e){
    var that = this;
    var money = e.detail.value;
    if(money > that.data.info.money)
    {
      wx.showToast({
        title: '余额不足',
      })
    }else{
      that.setData({
        money:money,
        fee:parseFloat(money * that.data.base.agent_fee / 100,2)
      })
    }
    
  },
  tixianxieyi:function(){
    this.setData({
      rule_state:true
    })
  },
  close_zhe:function(){
    this.setData({
      rule_state:false
    }) 
  },
  tongyi:function(e){
    this.setData({
      rule_state:false,
      check_state:true
    })
  },
  submit:function(e){
    var that = this;
    var values = e.detail.value;
    values.bank_id = that.data.bank_id;
    values.bank_card = that.data.bank_card;
    values.bank_address = that.data.bank_address;
    values.bank_user = that.data.bank_user;
    values.hid = that.data.hid;
    values.zfb_id = that.data.zfb_id;
    values.zfb_name = that.data.zfb_name;
    values.zfb_number = that.data.zfb_number;
    values.openid = wx.getStorageSync('openid');
    values.fee = that.data.fee;
    values.sh = that.data.base.is_agent;
    values.position = that.data.position;
    if(values.money == '')
    {
      wx.showToast({
        title: '请输入提现金额',
        icon:"none"
      })
    }else if(e.detail.value.check.length==0){
      wx.showToast({
        title: '请同意提现协议',
        icon:"none"
      })
    }else if(values.money > that.data.info.money){
      wx.showToast({
        title: '余额不足',
      })
    }else{
      console.log(values);
      app.util.request({
        "url":"entry/wxapp/regin.hospital_tixian",
        data:values,
        success:function(res){
          wx.showToast({
            title: '申请成功',
          })
          setTimeout(() => {
            wx.navigateTo({
              url: '/hyb_yl/jigou/pages/index/index',
            })
          }, 100);
        }
      })
    }
  },
  qbtixian:function(e){
    
    this.setData({
      money:this.data.info.money,
      fee:parseFloat(this.data.info.money * this.data.base.agent_fee/100,2)
    })
  },

  gobankcord:function(){
    wx.navigateTo({
      url:"/hyb_yl/jigou/pages/bank_card/bank_card?keyword=tixian",
    })
  },
  gozfb:function(){
    wx.navigateTo({
      url:"/hyb_yl/jigou/pages/zfb_page/zfb_page?keyword=tixian",
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.getHospital();
    that.getBase();
  },
  // 获取基础设置
  getBase:function(){
    var that = this;
    app.util.request({
      'url':"entry/wxapp/regin.jiesuanset",
      success:function(res){
        that.setData({
          base:res.data,
          weixin_content:res.data.weixin_content,
          bank_content:res.data.bank_content,
          zfb_content:res.data.zfb_content,
          xieyi:res.data.weixin_content,
        })
      }
    })
  },
  // 获取机构详情
  getHospital:function(){
    var that = this;
    app.util.request({
      'url':"entry/wxapp/regin.hospitals",
      data:{
        openid:wx.getStorageSync('openid'),
      },
      success:function(res){
        that.setData({
          info:res.data,
          hid:res.data.hid
        })
        var bank = res.data.bank;
        var zfb = res.data.zfb;
        if(bank.length > 0)
        {
          that.setData({
            bank_id:bank[0].id,
            bank_card:bank[0].number,
            bank_address:bank[0].bank_name,
            bank_user:bank[0].name
          })
        }
        if(zfb.length > 0)
        {
          that.setData({
            zfb_id:zfb[0].id,
            zfb_name:zfb[0].name,
            zfb_number:zfb[0].number
          })
        }
      }
    })
  },
  txtype:function(e){
    var type = e.detail.value;
    console.log(e);
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})